{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "120"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "def product(*arg):\n",
    "    result = 1\n",
    "    for i in arg:\n",
    "        result *= i\n",
    "    return result\n",
    "\n",
    "print(product(1,2,3,4,5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "321cba\n"
     ]
    }
   ],
   "source": [
    "def rev(s):\n",
    "    return s[::-1]\n",
    "\n",
    "print(rev(\"abc123\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "abc123 把 a 放到最后\n",
      "bc123 把 b 放到最后\n",
      "c123 把 c 放到最后\n",
      "123 把 1 放到最后\n",
      "23 把 2 放到最后\n",
      "321cba\n"
     ]
    }
   ],
   "source": [
    "# 递归来实现\n",
    "# rev(\"abc123\")\n",
    "#    rev(\"bc123\")+\"a\"\n",
    "#     rev(\"c123\")+\"b\"\n",
    "#         rev(\"123\")+\"c\"\n",
    "#              rev(\"3\")\n",
    "def rev2(s):\n",
    "    if len(s)>1:\n",
    "        print(s,\"把\",s[0],\"放到最后\")\n",
    "        return rev2(s[1:])+s[0]\n",
    "    else:\n",
    "        return s\n",
    "\n",
    "print(rev2(\"abc123\"))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
